package com.bayair.doctor.utils;

import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bayair.doctor.App;
import com.bayair.doctor.R;
import com.bayair.doctor.widget.LinearItemDecoration;
import com.example.library.utils.DensityUtils;
import com.tencent.qcloud.tim.uikit.component.CustomLinearLayoutManager;

public class WidgetUtils {

    private WidgetUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 让Activity全屏显示
     *
     * @param activity
     */
    public static void requestFullScreen(@NonNull Activity activity) {
        activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    //===============recyclerView=============//

    /**
     * 初始化RecyclerView
     *
     * @param recyclerView
     * @param adapter
     */
    public static void bindRecyclerView(@NonNull RecyclerView recyclerView,RecyclerView.Adapter adapter) {
        recyclerView.setLayoutManager(new CustomLinearLayoutManager(recyclerView.getContext()));
        recyclerView.setAdapter(adapter);
    }

    /**
     * 初始化RecyclerView
     *
     * @param recyclerView
     * @param adapter 分割线的高度
     */
    public static void bindRecyclerViewWithDiver(@NonNull RecyclerView recyclerView,RecyclerView.Adapter adapter,int orientation) {
        recyclerView.setLayoutManager(new CustomLinearLayoutManager(recyclerView.getContext(),orientation,false));
        LinearItemDecoration ItemDecoration = new LinearItemDecoration.Builder(recyclerView.getContext())
                .setColor(App.getContext().getResources().getColor(R.color.line_gray_shallow))
                .setPadding(DensityUtils.dp2px(10))
                .setSpan(DensityUtils.dp2px(1))
                .build();
        recyclerView.addItemDecoration(ItemDecoration);
        recyclerView.setAdapter(adapter);
    }
}
